#include "city.h"

City::City()
{
    this->city_name = "";
    this->city_country = "";
    this->city_new = 0;
    this->city_now = 0;
    this->city_cure = 0;
    this->city_dead = 0;
    this->city_all = 0;
    this->city_day = QDate(1,1,1);
}

City::City(QString name, QString country, int New, int now, int all, int cure, int dead, QDate day)
{
    this->city_name = name;
    this->city_country = country;
    this->city_new = New;
    this->city_now = now;
    this->city_all = all;
    this->city_cure = cure;
    this->city_dead = dead;
    this->city_day = day;
}

City::City(const City &cit)
{
    this->city_name = cit.city_name;
    this->city_country = cit.city_country;
    this->city_new = cit.city_new;
    this->city_now = cit.city_now;
    this->city_all = cit.city_all;
    this->city_cure = cit.city_cure;
    this->city_dead = cit.city_dead;
    this->city_day = cit.city_day;
}

City City::operator+(City &cit)
{
    City ret;
    ret.city_name = this->city_name;
    ret.city_country = this->city_country;
    ret.city_new = this->city_new + cit.city_new;
    ret.city_now = this->city_now + cit.city_now;
    ret.city_cure = this->city_cure + cit.city_cure;
    ret.city_dead = this->city_dead + cit.city_dead;
    ret.city_all = this->city_all + cit.city_all;
    return ret;
}

City &City::operator+=(City &cit)
{
    *this = *this + cit;
    return *this;
}

QString City::getKey()
{
    return this->city_name+this->city_country+this->city_day.toString("yyyy年MM月dd日");
}

QString City::get_name()
{
    return this->city_name;
}

QString City::get_country()
{
    return this->city_country;
}

int City::get_new()
{
    return this->city_new;
}

int City::get_now()
{
    return this->city_now;
}

int City::get_all()
{
    return this->city_all;
}

int City::get_cure()
{
    return this->city_cure;
}

int City::get_dead()
{
    return this->city_dead;
}

QDate City::get_day()
{
    return this->city_day;
}

void City::set_name(QString name)
{
    this->city_name = name;
}

void City::set_country(QString country)
{
    this->city_country = country;
}

void City::set_new(int New)
{
    this->city_new = New;
}

void City::set_now(int now)
{
    this->city_now = now;
}

void City::set_cure(int cure)
{
    this->city_cure = cure;
}

void City::set_dead(int dead)
{
    this->city_dead = dead;
}

void City::set_all(int all)
{
    this->city_all = all;
}

void City::set_day(QDate day)
{
    this->city_day = day;
}

QTextStream &operator>>(QTextStream &in, City &cit)
{
    QString line = in.readLine();
    QStringList stringlist = line.split("\3");

    cit.city_name = stringlist[0];
    cit.city_country = stringlist[1];
    cit.city_new = stringlist[2].toInt();
    cit.city_now = stringlist[3].toInt();
    cit.city_all = stringlist[4].toInt();
    cit.city_cure = stringlist[5].toInt();
    cit.city_dead = stringlist[6].toInt();
    cit.city_day = QDate::fromString(stringlist[7],"yyyy年MM月dd日");

    return in;
}

QTextStream &operator<<(QTextStream &out, City &cit)
{
    out << cit.city_name << "\3" << cit.city_country << "\3"
        << cit.city_new << "\3" << cit.city_now << "\3"
        << cit.city_all << "\3" << cit.city_cure << "\3"
        << cit.city_dead << "\3" << cit.city_day.toString("yyyy年MM月dd日");
    return out;
}
